home *** CD-ROM | disk | FTP | other *** search
-
- #include "BuildControl.h"
-
-
-
- #if defined(qUseDumpFile)
- #include "DumpHeader.h"
- #else
- #include <Resources.h>
- #endif
-
- #include "FloatingWindowSupport.h"
-
-
-
- extern void DoActivate(WindowPtr, Boolean);
- extern Boolean GetLastVisibleState(WindowPtr);
- extern void SetLastVisibleState(WindowPtr, Boolean);
-
-
- //-----------------------------------------------------------------------
- // If the hit window is a floater and isn't the frontmost floater, or
- // if its a nonfloater and it isn't the frontmost nonfloater,
- // we should select it.
- //-----------------------------------------------------------------------
- Boolean NeedsSelect(WindowPtr win)
- {
- Boolean isntSelected = false;
-
- if ((!IsFloatingWindow(win)) && (win != FrontNonFloatingWindow()))
- isntSelected = true;
-
- else if ((IsFloatingWindow(win)) && (win != FrontWindow()))
- isntSelected = true;
-
- return isntSelected;
- }
-
- //-----------------------------------------------------------------------
-
- Boolean IsFloatingWindow(WindowPtr win)
- {
- return ((win != NULL)
- && (((WindowPeek) win)->windowKind == kApplicationFloaterKind));
- }
-
- //-----------------------------------------------------------------------
-
- Boolean IsModalWindow(WindowPtr win)
- {
- short variant;
- Boolean isModal = false;
-
- if (win != NULL) {
- variant = GetWVariant((WindowPtr) win);
- if ((((WindowPeek) win)->windowKind == dialogKind)
- && ((variant == dBoxProc) || (variant == movableDBoxProc)))
- isModal = true;
- }
-
- return isModal;
- }
-
- //-----------------------------------------------------------------------
- // ActivateWindow
- //
- // Hilites and calls its activate handler.
- //-----------------------------------------------------------------------
- void ActivateWindow(WindowPtr win)
- {
- HighlightActivateWindow(win, true);
- }
-
- //-----------------------------------------------------------------------
- // DeactivateWindow
- //
- // Unhilites and calls its activate handler.
- //-----------------------------------------------------------------------
- void DeactivateWindow(WindowPtr win)
- {
- HighlightActivateWindow(win, false);
- }
-
- //-----------------------------------------------------------------------
- // HighlightActivateWindow
- //
- // Common code for ActivateWindow and DeactivateWindow. Does actual
- // highlighting and calling of the activate handler.
- //-----------------------------------------------------------------------
- void HighlightActivateWindow(WindowPtr win, Boolean activate)
- {
- //
- // Calls back to the application shell (gross) to perform the
- // activates needed, since we're dummying them up for our purposes.
- //
- HiliteWindow(win, activate);
- DoActivate(win, activate);
- }
-
- //-----------------------------------------------------------------------
-
- void DragThisWindow(WindowPtr win, Point startPoint, const Rect *bounds)
- {
- Rect dragRect;
- KeyMap keyMap;
- GrafPtr savePort;
- GrafPtr windowMgrPort;
- RgnHandle dragRegion;
- RgnHandle windowContentRegion;
- long dragResult;
- short topLimit;
- Boolean commandKeyDown;
-
- if (WaitMouseUp()) {
- //
- // Adjust the top of the dragging rectangle
- //
- topLimit = GetMBarHeight() + 4;
- dragRect = *bounds;
- if (dragRect.top < topLimit)
- dragRect.top = topLimit;
-
- GetPort(&savePort);
- GetWMgrPort(&windowMgrPort);
- SetPort(windowMgrPort);
- SetClip(GetGrayRgn());
-
- //
- // Check to see if the command key is down. If it is, don’t
- // bring the window to the front after the move.
- //
- GetKeys(keyMap);
- commandKeyDown = ((keyMap[1] & 0x8000) != 0);
-
- if ((commandKeyDown == true) || (!IsFloatingWindow(win))) {
- if (commandKeyDown == false)
- //
- // If there are floating windows, clip the dragging
- // outline to draw behind the floaters.
- //
- ClipAbove(FrontNonFloatingWindow());
- else
- //
- // If the command key was down, clip the outline to
- // draw behind any windows above the window being dragged.
- //
- ClipAbove(win);
- }
-
- dragRegion = NewRgn();
- CopyRgn(((WindowPeek) win)->strucRgn, dragRegion);
- dragResult = DragGrayRgn(dragRegion, startPoint, &dragRect,
- &dragRect, noConstraint, NULL);
-
- SetPort(savePort);
-
- if (dragResult != 0) {
- short newHoriz, newVert;
- short horizOffset, vertOffset;
-
- horizOffset = dragResult & 0xFFFF;
- vertOffset = dragResult >> 16;
- //
- // Only move it if it stayed inside the dragging box.
- //
- if (vertOffset != -32768) {
- windowContentRegion = ((WindowPeek) win)->contRgn;
- newHoriz = (*windowContentRegion)->rgnBBox.left + horizOffset;
- newVert = (*windowContentRegion)->rgnBBox.top + vertOffset;
- MoveWindow(win, newHoriz, newVert, false);
- }
- }
-
- //
- // Bring the window forward if the command key wasn’t down
- //
- if (commandKeyDown == false)
- SelectThisWindow(win);
-
- DisposeRgn(dragRegion);
- }
- }
-
- //-----------------------------------------------------------------------
-
- void SelectThisWindow(WindowPtr win)
- {
- WindowPtr currentFront;
- WindowPtr lastFloat;
- Boolean itFloats;
-
- itFloats = IsFloatingWindow(win);
-
- if (itFloats)
- currentFront = FrontWindow();
-
- else {
- currentFront = FrontNonFloatingWindow();
- lastFloat = LastFloatingWindow();
- }
-
- if (currentFront != win) {
- //
- // Selecting floating windows is easy since they’re always active
- //
- if (itFloats)
- BringToFront(win);
-
- else {
- //
- // If there are no floating windows, call SelectWindow
- //
- if (lastFloat == NULL)
- SelectWindow(win);
-
- else {
- //
- // Else we a nonfloating window has been selected and
- // there are floaters. Deactivate the window
- // currently in front, send the selected window behind
- // the last floater and activate it.
- //
- DeactivateWindow(currentFront);
- SendBehind(win, lastFloat);
- ActivateWindow(win);
- }
- }
- }
- }
-
- //-----------------------------------------------------------------------
- // Return the first visible window that is not a floating window.
- //-----------------------------------------------------------------------
- WindowPtr FrontNonFloatingWindow()
- {
- WindowPtr win = FrontWindow();
-
- while (win != NULL) {
- if ((!IsFloatingWindow(win)) && (!IsModalWindow(win))
- && ((WindowPeek) win)->visible == true)
- break;
-
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- }
-
- return win;
- }
-
- //-----------------------------------------------------------------------
- // Return the last floating window, whether it is visible or not, or
- // NULL if there are no floating windows.
- //-----------------------------------------------------------------------
- WindowPtr LastFloatingWindow(void)
- {
- WindowPtr win;
- WindowPtr lastFloat;
-
- win = (WindowPtr) LMGetWindowList();
- lastFloat = NULL;
-
- while (win != NULL) {
- if (IsFloatingWindow(win))
- lastFloat = win;
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- }
-
- return lastFloat;
- }
-
-
- //-----------------------------------------------------------------------
-
- void PutNonFloatingWindowInList(WindowPtr win, WindowPtr behind)
- {
- require(IsFloatingWindow(win) == false, PuttingFloaterInWrongList);
-
- if (behind == (WindowPtr) -1) {
- //
- // If -1, put this window at the front of the non floater list.
- //
- behind = LastFloatingWindow();
-
- if (behind == NULL)
- BringToFront(win);
- }
- else
- SendBehind(win, behind);
-
- PuttingFloaterInWrongList:
- NormalizeWindowList();
- return;
- }
-
- //-----------------------------------------------------------------------
-
- void ShowThisWindow(WindowPtr win)
- {
- WindowPtr behind;
- WindowPtr frontNonFloater;
- Boolean activateIt = false;
-
- NormalizeWindowList();
- if ((((WindowPeek) win)->visible != false))
- return;
-
- frontNonFloater = FrontNonFloatingWindow();
-
- if (!IsFloatingWindow(win)) {
- //
- // We're showing a non-floater. Grab the next window and if
- // its the frontmost non floater, unhilite it and prepare win
- // to be hilited.
- //
- behind = (WindowPtr) ((WindowPeek) win)->nextWindow;
-
- if ((behind == frontNonFloater) || (frontNonFloater == NULL)) {
- if (behind != NULL)
- DeactivateWindow(behind);
-
- ((WindowPeek) win)->hilited = true;
- activateIt = true;
- }
- }
- else {
- //
- // We're showing a floater. Check to see if a modal window is
- // up before trying to highlight this one. If so, show this
- // but don't hilite it.
- //
- if ((frontNonFloater != NULL) && (frontNonFloater == FrontWindow())
- && (IsModalWindow(frontNonFloater)))
- ((WindowPeek) win)->hilited = false;
-
- else {
- ((WindowPeek) win)->hilited = true;
- activateIt = true;
- }
- }
-
- //
- // Show the window and activate/hilite it if necessary
- //
- ShowHide(win, true);
-
- if (activateIt)
- DoActivate(win, true);
- }
-
- //-----------------------------------------------------------------------
- // HideThisWindow
- //
- // Hide the specified window. If it is frontmost, move it behind
- // the window immediately behind it, like HideWindow does.
- //-----------------------------------------------------------------------
- void HideThisWindow(WindowPtr windowToHide)
- {
- WindowPtr behind, newFront;
- Boolean itFloats;
-
- if (((WindowPeek) windowToHide)->visible == false)
- return;
-
- itFloats = IsFloatingWindow(windowToHide);
-
- DeactivateWindow(windowToHide);
- ShowHide(windowToHide, false);
-
- behind = (WindowPtr) ((WindowPeek) windowToHide)->nextWindow;
-
- //
- // If there is a window to move this one behind and it's not a floater,
- // or if it is a floater, and we're moving it behind another floater,
- // go ahead and reorder the list.
- //
- if ((behind != NULL) && (behind != windowToHide)
- && ((itFloats == false)
- || ((itFloats == true) && (IsFloatingWindow(behind)))))
- SendBehind(windowToHide, behind);
-
- if (itFloats == false)
- newFront = FrontNonFloatingWindow();
- else
- //
- // If the last window we hid was a floater, we shouldn't have to
- // activate anything because all should be fine.
- //
- newFront = NULL;
-
- if (newFront != NULL)
- ActivateWindow(newFront);
- }
-
-
-
- //-----------------------------------------------------------------------
- // SuspendFloaters
- //
- // Hide any visible floating windows and deactivate the frontmost
- // document window.
- //-----------------------------------------------------------------------
- void SuspendFloaters(void)
- {
- WindowPtr win;
- Boolean windowIsVisible;
-
- win = (WindowPtr) LMGetWindowList();
- if (!IsFloatingWindow(win))
- return;
-
- do {
- windowIsVisible = ((WindowPeek) win)->visible;
- SetLastVisibleState(win, windowIsVisible);
- if (windowIsVisible)
- ShowHide(win, false);
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- } while ((win != NULL) && (IsFloatingWindow(win)));
-
- //
- // The floating windows are now hidden. Deactivate the
- // first visible document window.
- //
- win = FrontNonFloatingWindow();
- if (win != NULL)
- DeactivateWindow(win);
- }
-
- //-----------------------------------------------------------------------
- // ResumeFloaters
- //
- // Reveal and activate floating windows that were hidden at suspend.
- // The frontmost document is also activated.
- //-----------------------------------------------------------------------
- void ResumeFloaters(void)
- {
- WindowPtr win;
- Boolean windowWasVisible;
-
- NormalizeWindowList();
- win = (WindowPtr) LMGetWindowList();
- if (!IsFloatingWindow(win))
- return;
-
- do {
- windowWasVisible = GetLastVisibleState(win);
- if (windowWasVisible) {
- ShowHide(win, true);
- ActivateWindow(win);
- }
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- } while ((win != NULL) && (IsFloatingWindow(win)));
-
- //
- // The floating windows have been revealed. Activate the
- // first document window as well.
- //
- win = FrontNonFloatingWindow();
- if (win != NULL)
- ActivateWindow(win);
- }
-
- //-----------------------------------------------------------------------
-
- void NormalizeWindowList()
- {
- WindowPtr current = (WindowPtr) LMGetWindowList();
- WindowPtr next, behind = NULL;
-
- //
- // Put modal windows in front
- //
- while (current != NULL) {
- next = (WindowPtr) ((WindowPeek) current)->nextWindow;
-
- if ((current != NULL) && (IsModalWindow(current))) {
- if (behind == NULL) {
- if (current != (WindowPtr) LMGetWindowList())
- BringToFront(current);
- }
- else if (current != (WindowPtr) ((WindowPeek) behind)->nextWindow)
- SendBehind(current, behind);
-
- behind = current;
- }
- current = next;
- }
-
- //
- // Put floating windows behind last modal
- //
- current = (WindowPtr) LMGetWindowList();
-
- while (current != NULL) {
- next = (WindowPtr) ((WindowPeek) current)->nextWindow;
-
- if ((current != NULL) && (IsFloatingWindow(current))) {
- if (behind == NULL) {
- if (current != (WindowPtr) LMGetWindowList())
- BringToFront(current);
- }
- else if (current != (WindowPtr) ((WindowPeek) behind)->nextWindow)
- SendBehind(current, behind);
-
- behind = current;
- }
- current = next;
- }
- }
-
- //-----------------------------------------------------------------------
- // Call this before EVER showing a modal window.
- //-----------------------------------------------------------------------
- void PrepareForModalWindow()
- {
- WindowPtr win;
-
- win = FrontWindow();
- while (win != NULL) {
- if (((WindowPeek) win)->visible == true)
- DeactivateWindow(win);
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- }
- }
-
- //-----------------------------------------------------------------------
- // Call this after dismissing a modal window.
- //
- // PowerPlant does this very nicely..
- //
- // Starting with the front window, activate all visible windows up
- // to and including the first visible non-floating window.
- // Why this works:
- // > If the front window is modal, it gets activated and
- // the loop stops because it's not floating.
- // > If the front window is floating, windows keep getting
- // activated until the first regular window is activated.
- // > If the front window is regular, it gets activated and
- // the loop stops because it's not floating.
- //-----------------------------------------------------------------------
- void RecoverFromModalWindow()
- {
- WindowPtr win;
-
- NormalizeWindowList();
- win = FrontWindow();
- while (win != NULL) {
- if (((WindowPeek) win)->visible == true) {
- ActivateWindow(win);
-
- if (IsFloatingWindow(win) == false)
- break;
- }
- win = (WindowPtr) ((WindowPeek) win)->nextWindow;
- }
- }